package com.example.plus5;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.example.plus5.R.drawable;
import android.R.color;
import android.os.Bundle;
import android.widget.TableRow.LayoutParams;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Appointments extends Activity {
	private SharedPreferences appointmentsEntered;
	private TableLayout appointmentRows;
	private TextView appointmentDay;
	private TextView appointmentTime;
	private TextView appointmentName;
	private Button editAppButton;
	private Button deleteAppButton;
	private Button enableAppButton;
	
	
	private ArrayList<appointment> allAppointments;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent intent = getIntent();
		setContentView(R.layout.activity_appointments);
		
		//appointmentsEntered = getSharedPreferences("appointmentList", MODE_PRIVATE);
		
		//updateAppList(null);
		
	}
	
	protected void onResume(){
		super.onResume();
	
		
		/*appointment newAppointment = (appointment) getIntent().getSerializableExtra("appointment");		
		updateAppList(newAppointment);*/
		Intent intent = getIntent();
		String toAdd = intent.getStringExtra(AddAppointment.EXTRA_MESSAGE);
		insertAppointmentInScrollView(toAdd);
		
		
		
		
	}
	
/*	private void updateAppList(appointment appointmentToAdd) {
		// TODO Auto-generated method stub
		appointment[] holderST = appointmentsEntered.getAll().keySet().toArray(new appointment[0]);
		allAppointments = new ArrayList<appointment>(Arrays.asList(holderST));
		
		allAppointments.add(appointmentToAdd);
		Collections.sort(allAppointments);*/
		
	/*	if(appointmentToAdd != null){
			
			insertAppointmentInScrollView(appointmentToAdd);
			}	*/	
			
			
		
		
		
	
	
	private void insertAppointmentInScrollView(String appointmentToAdd) {
		// TODO Auto-generated method stub
		TableLayout appointmentRows = (TableLayout) findViewById(R.id.appointmentRows);
		TableRow tr1 = new TableRow(this);
		TableRow tr2 = new TableRow(this);
		LayoutParams lp= new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		tr1.setLayoutParams(lp);
		tr2.setLayoutParams(lp);
		LayoutParams daylp = new LayoutParams(24,24, 6 );
		LayoutParams timelp = new LayoutParams(24,24, 4 );
		LayoutParams buttonlp = new LayoutParams(24,24, 4 );
		
		TextView appointmentDay = new TextView(this);
		appointmentDay.setLayoutParams(daylp);
		appointmentDay.setTextColor(color.black);
		appointmentDay.setBackgroundColor(color.white);
		appointmentDay.setText(appointmentToAdd);
		
/*		TextView appointmentTime = new TextView(this);
		appointmentDay.setLayoutParams(timelp);
		appointmentDay.setTextColor(color.holo_red_light);
		appointmentDay.setText(appointmentToAdd.getTime().toString());*/
		
		Button enableButton = new Button(this);
		enableButton.setBackgroundColor(color.darker_gray);
		enableButton.setText("Disable");
		enableButton.setTextColor(color.holo_red_light);
		enableButton.setTextSize(24);
		
		Button editButton = new Button(this);
		editButton.setBackgroundResource(R.drawable.pencil48);
		editButton.setPadding(4, 4, 4, 4);
		
		Button deleteButton = new Button(this);
		enableButton.setBackgroundColor(color.darker_gray);
		enableButton.setText("Disable");
		enableButton.setTextColor(color.holo_red_light);
		enableButton.setTextSize(24);
		
		tr1.addView(appointmentDay);
		tr1.addView(enableButton);
		tr1.addView(editButton);
		tr1.addView(deleteButton);
		
		appointmentRows.addView(tr1, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		
		
		
	}
	public void enterAppointment(View v){
		Intent intent = new Intent(Appointments.this, AddAppointment.class);
		startActivity(intent);
		
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.appointments, menu);
		return true;
	}
}